# !/usr/bin/env python
# -*- coding: utf-8 -*-
# ///////////////////////////////////////////////////////////////
# @File    :   medicalReportForm.py
# @Time    :   2024/08/22 14:45:52
# @Author  :   kai.luo
# @Version :   1.0.0
# @Desc    :   None
# ///////////////////////////////////////////////////////////////

# type: ignore
from moudles.MedicalReportForm.commonLibrary.common import *
from paddleocr import PaddleOCR, PPStructure, draw_ocr
from moudles.MedicalReportForm.chongqinModel.chongqin import Chongqin
from moudles.MedicalReportForm.sichuanModel.sichuan import Sichuan


class MedicalReportForm(object):
    """
    医疗报告单
    Args:
        object (_type_): _description_
    """

    def __init__(self) -> None:
        # 初始化参数

        self.imagePath_reportFormData_dict = dict()  # 所有图片的数据字典

    def parserPPStructure(self, img_path):
        """
            # table_engine = PPStructure(show_log=True, use_gpu=False)
            # img = cv2.imread(img_path)
            # result = table_engine(img, True)
            # res = result[0].get('res', '')
            Args:
                img_path (_type_): _description_
        """

        ocr = PaddleOCR(use_gpu=False, use_angle_cls=True, lang="ch", det_model_dir="./model/det",
                        rec_model_dir="./model/rec/", cls_model_dir="./model/cls/")
        result = ocr.ocr(img_path, cls=True)

        # 判断该数据数据那个省市片区的报告单
        area = getImageArea(result[0])

        # 默认参数
        headerHeight = float(110)
        foortHeight = float(120)
        del_col_name_list = ['提示', '标志']
        add_col_name_dict = dict()

        # 判断区域属性
        if area[0] == 'chongqin':
            if area[1] == 'kingmend':  # 金域医学
                headerHeight = float(160)
                foortHeight = float(120)
            elif area[1] == 'maternalChildHospital':  # 妇幼保健院
                headerHeight = float(116)
                foortHeight = float(120)
                del_col_name_list = ['提示', '标志', 'CT值']
                add_col_name_dict = {1: '项目中文名称'}
            chongqin_model = Chongqin()
            # print(f'result[0]-------{result[0]}')
            image_data = chongqin_model.getChongqinImageData(
                result[0], headerHeight, foortHeight, del_col_name_list, add_col_name_dict)
        elif area[0] == 'sichuan':
            sichuan_model = Sichuan()
            # print(f'result[0]---{result[0]}')
            image_data = sichuan_model.getSichuanImageData(
                result[0], headerHeight, foortHeight, del_col_name_list, add_col_name_dict)

        # 保存图片路径对应的数据
        # self.imagePath_reportFormData_dict.setdefault(img_path, image_data)
        # print(f'self.image_formData_dict----{self.image_formData_dict}')

        return image_data
